package com.iwop.moto.controller;

import com.iwop.moto.comm.ErrCode;
import com.iwop.moto.model.FCommonCouponBack;
import com.iwop.moto.model.ResultModel;
import com.iwop.moto.service.FCommonCouponBackService;
import com.iwop.moto.utils.stringUtil.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * Created by chenzq on 2016/12/7.
 */
@Controller
public class MCommonCouponController extends BaseController {

    @Autowired
    private FCommonCouponBackService fCommonCouponBackService;


    /**
     * 后台添加优惠券
     *
     * @param FCommonCouponBack
     * @return ResultModel
     */
    @RequestMapping("/consumer/commonpon/insert")
    @ResponseBody
    public ResultModel insert(@ModelAttribute FCommonCouponBack fCommonCouponBack) {
        if (StringUtils.isEmpty(fCommonCouponBack.getUserId()) || StringUtils.isEmpty(fCommonCouponBack.getCouponId()))
            return getErr(ErrCode.ERROR_SYSTEM);
        if (StringUtils.isEmpty(fCommonCouponBack.getOrderId())) return getErr(ErrCode.ERROR_SYSTEM);
        int insert = fCommonCouponBackService.insert(fCommonCouponBack);
        if (insert == 1) {
            return getSucceed(null, ErrCode.SUCCEED);
        }
        return getErr(ErrCode.ERROR_SYSTEM);
    }



}
